/**
 * Created by forcht on 2018/7/14.
 */
public class Solution {
    public int removeElement(int[] A, int elem) {
       int i=0;
       int j=A.length-1;
       while (i<=j){
           while (i<=j&&A[i]!=elem)i++;
           while (i<=j&&A[j]==elem)j--;
           if(i<=j){
               A[i]=A[j];
               i++;
               j--;
           }
       }
       return i;
    }

    public static void main(String[] args) {
        Solution solution=new Solution();
        System.out.println(solution.removeElement(new int[]{2,7,8},2));
    }
}
